import { Ref } from "vue";

export type FixedOptions = {
  wrap: Ref<HTMLElement>;
  contain: Ref<HTMLElement>;
  height: number;
  bufferNumber: number;
  data: Ref<any[]>;
  offsetTop?: number;
};

export type FixedWrapOptions = {
  height: number;
  offsetTop?: number;
  bufferNumber: number;
};

export type Virtual = {
  type: "fix" | "auto";
  options: FixedWrapOptions;
};

export type TableSetting = {
  show: boolean; // 是否显示、排序设置
  storage: boolean; // 是否存储设置
  storageKey?: string; // 存储设置key
};

export type SearchSetting = {
  show?: boolean; // 是否显示搜索
  storage?: boolean; // 是否存储设置
  storageKey?: string; // 存储设置key
  viewShow?: boolean; // 是否显示视图设置
  isSearchRange?: boolean; // 是否搜索范围
  isFilter?: boolean;
  title?: string; // 总数标题
};

export type OperatorList = {
  label: string; // 逻辑名称
  value: string; // 逻辑值
};

export type FilterSetting = {
  type?: "select" | "date" | "input"; // 过滤类型
  operator?: OperatorList[] | Function; // 操作符列表
  value?: OperatorList[] | Function; // 选择值
  [key: string]: any; // 不同组件传参不同
};

export type Pagination = {
  pageSize?: number;
  currentPage?: number;
  total?: number;
};

export type TableOptions = {
  minWidth?: number; // 最小列宽 存在赋值，不存在自适应
  headerFixed?: boolean; // 是否固定表头
  setting?: TableSetting; //  表格设置
  searchSetting?: SearchSetting; // 搜索配置
  virtual?: Virtual; // 虚拟滚动
};

export type TableColumn = {
  type?: string;
  title: string;
  key: string;
  width?: number;
  isHidden?: boolean; // 是否隐藏 -- 取决于用户
  isFixed?: boolean; // 是否固定列 -- 取决于用户
  isShowSort?: boolean; // 是否显示排序
  sortType?: "" | "ASC" | "DESC"; // 排序类型
  isMoreActive?: boolean; // 是否更多激活
  isSearch?: boolean; // 是否参与模糊搜索匹配
  filter?: FilterSetting; // 过滤条件配置
  align?: "left" | "center" | "right";
  className?: string; // 自定义类名
  tableName?: string; // 后端表名
  columnKey?: string; // 后端字段名
};

export type TableData = {
  [key: string]: any;
};

export interface TableProps {
  data?: TableData[];
  columns: TableColumn[];
  customContentLayout?: any[];
  options?: TableOptions;
  pagination?: Pagination;
  api?: Function | null;
  afterApiTransformData?: Function | null;
}
